//==========================================================================
// Copyright (c) 2000-2008,  Elastos, Inc.  All Rights Reserved.
//==========================================================================
#include <elasys_server.h>
#include "keyboard.h"
#include "mouse.h"
#include "shadow.h"

Boolean CShadow::GetFocused(Int32 x, Int32 y)
{
    return (((x < m_posX) || (x >= m_posX + m_width)
           || ( y < m_posY) || (y >= m_posY + m_height))
           ? FALSE : TRUE);
}

CKeyboard * CShadow::GetKeyboard()
{
    return CKeyboard::S_Get(m_environmentId);
}

CMouse * CShadow::GetMouse()
{
    return CMouse::S_Get(m_environmentId);
}

// -------------------------------------------

CShadow * CShadowManager::GetFocus(
        /* [in] */ Int32 x,
        /* [in] */ Int32 y)
{
    assert(!m_shadowList.IsEmpty());
    CShadow * pShadow = (CShadow *)m_shadowList.Next();
    return (pShadow->GetFocused(x,y) ? pShadow : NULL);
}

CShadow * CShadowManager::GetFocus()
{
    assert(!m_shadowList.IsEmpty());
    return (CShadow *)m_shadowList.Next();
}

void CShadowManager::AddShadow(
        /* [out] */ CShadow * pShadow)
{
    assert(pShadow->IsEmpty());
    assert(m_shadowList.IsEmpty());
    m_shadowList.InsertLast(pShadow);
}

void CShadowManager::RemoveShadow(
        /* [out] */ CShadow * pShadow)
{
    pShadow->Detach();
    assert(m_shadowList.IsEmpty());
}

static CShadowManager g_shadowManager;
CShadowManager * GetShadowManager()
{
    return &g_shadowManager;
}

